from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

Builder.load_string('''
<myLayout>
    BoxLayout:
        orientation:'vertical'
        spacing:15
        padding:38
        Button:
            id:0
            text:'0'
            size_hint:(.5, .5)
            pos_hint:{"center_x": .5, "center_y": .5}
            on_press:root.on_press_button(self.text)
        Button:
            id:1
            text:'1'
            size_hint:(.5, .5)
            pos_hint:{"center_x": .5, "center_y": .5}            
            on_press:root.on_press_button(self.text)
        Button:
            id:2
            text:'2'
            size_hint:(.5, .5)
            pos_hint:{"center_x": .5, "center_y": .5}            
            on_press:root.on_press_button(self.text)
        Button:
            id:3
            text:'3'
            size_hint:(.5, .5)
            pos_hint:{"center_x": .5, "center_y": .5}            
            on_press:root.on_press_button(self.text)
        Button:
            id:4
            text:'4'
            size_hint:(.5, .5)
            pos_hint:{"center_x": .5, "center_y": .5}            
            on_press:root.on_press_button(self.text)   
        Button:
            id:5
            text:'5'
            size_hint:(.5, .5)
            pos_hint:{"center_x": .5, "center_y": .5}            
            on_press:root.on_press_button(self.text)
        Button:
            id:6
            text:'6'
            size_hint:(.5, .5)
            pos_hint:{"center_x": .5, "center_y": .5}            
            on_press:root.on_press_button(self.text)                                 
''')


class myLayout(BoxLayout):
    def __init__(self, **kwargs):
        super(myLayout, self).__init__(**kwargs)

    def on_press_button(self, instance):
        print('你按下了{}键'.format(instance))


class boxLayoutExample(App):
    def build(self):
        return myLayout()

boxLayoutExample().run()
